package com.example.itensyuan0609.fragment;


import android.animation.ValueAnimator;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;

import com.example.itensyuan0609.R;

/**
 * A simple {@link Fragment} subclass.
 */
public class TwoFragment extends Fragment implements View.OnClickListener {
    private TextView tvbanben;
    private TextView tvguanyu;
    private View view;
    private TextView tv_guanyu;
    private LinearLayout ll_guanyu;

    public TwoFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.fragment_two, container, false);
        tvbanben = view.findViewById(R.id.tv_banben);
        tvguanyu = view.findViewById(R.id.tv_guanyu);
        ll_guanyu = view.findViewById(R.id.ll_guanyu);
        initView();
        return view;

    }

    public void initView() {
        FragmentActivity activity = getActivity();
        //获取包的管理员
        PackageManager packageManager = activity.getPackageManager();
        try {
            PackageInfo packageInfo = packageManager.getPackageInfo(activity.getPackageName(), 0);
            String versionName = packageInfo.versionName;
            tvbanben.setText("当前版本：" + versionName);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }


    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_guanyu:
                if (ll_guanyu.getVisibility() == View.GONE) {
                    animationOpen(ll_guanyu);
                } else {
                    animationClose(ll_guanyu);
                }
                break;
        }
    }

    private void animationOpen(View view) {
        view.setVisibility(View.VISIBLE);
    }

    private void animationClose(View view) {
        view.setVisibility(View.VISIBLE);
    }

    private void createDropAnimation(final View view, int strat, int end) {
        //属性动画
        ValueAnimator valueAnimator = ValueAnimator.ofInt(strat, end);
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                //获取动画的移动数据
                int value = (int) valueAnimator.getAnimatedValue();
                //获取布局参数
                ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
                //改变参数中的height的值
                layoutParams.height = value;
                //将改变之后的参数重新赋值给布局
                view.setLayoutParams(layoutParams);
            }
        });
    }
}
